package cn.cool;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;


public class DeadLock {
    private static final Lock lock_1 = new ReentrantLock();
    private static final Lock lock_2 = new ReentrantLock();


    public static void main(String[] args) {
        Thread thread_1 = new Thread(() -> {
            lock_1.lock();
            try {
                System.out.println("获取到 lock_1");
                lock_2.lock();
                try {
                    System.out.println("获取到 lock_2");
                }finally {
                    lock_2.unlock();
                }
            }finally {
                lock_1.unlock();
            }
        });

        Thread thread_2 = new Thread(() -> {
            lock_2.lock();
            try {
                System.out.println("获取到 lock_2");
                lock_1.lock();
                try {
                    System.out.println("获取到 lock_1");
                }finally {
                    lock_1.unlock();
                }
            }finally {
                lock_2.unlock();
            }
        });
        thread_1.start();
        thread_2.start();
    }
}
